<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>李宁体育管理系统</title>
    <link rel="shortcut icon" href="https://cdns.lining.com/shop/lining/theme/xth2/images/headfooter/favicon.ico">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	
	<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet"> 
    <link href="css/animate.min.css" rel="stylesheet">
 	<link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
  </head>
  <body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>宁聚日活动列表</h5>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form role="form" id="queryForm" class="form-inline">
                        <div class="form-group">
                            <input class="form-control" type="text" style="width:150px;" id="title" name="title"
                                   value="${map.title}" placeholder="标题"/>
                        </div>
                        <div class="input-group">
                            <button class="btn btn-primary" type="button" style="margin-bottom: 0px;"
                                    onclick="search();"><i class="fa fa-search"></i>&nbsp;查询
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins" id="tableShow">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                      <div class="btn-group hidden-xs" id="tableEventsToolbar" role="group">
                            <button type="button" class="btn btn-primary" title="添加宁聚日活动" id="addFlowButton"
                                    onclick="addOperator()">
                                <i class="glyphicon glyphicon-plus"></i>&nbsp;添加宁聚日活动
                            </button>
                        </div>
                        <table id="ChannelProductListTable" data-mobile-responsive="true"
                               data-click-to-select="true" data-unique-id="id">
                            <thead>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
        </div>
    </div>
    <div style="display: none;position: relative;
    top: -50px;" class="modal" id="myModal" tabindex="-1"role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>--%>
                <h4 class="modal-title" id="myModallabel">消息提示</h4>
            </div>
            <div class="modal-body">
                <span id="deletecontent"></span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm" onclick="confirm()">确定删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel" onclick="cancel()">取消删除</button>

            </div>
        </div>
    </div>
</div>
</div>


<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--时间选择-->
<script src="js/plugins/layer/laydate/laydate.js"></script>
<!--下拉框-->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
    var $table = $('#ChannelProductListTable');

    var search = function () {
        $table.bootstrapTable('refresh');
    }
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };

    $(document).ready(function () {
        //将表单元素和table属性转成json
        queryParams = function (params) {
            var temp = {};
            temp.currentResult = params.offset;
            temp.showCount = params.limit;
            var formParam = $('#queryForm').serializeArray();
            for (var i = 0; i < formParam.length; i++) {
                if (formParam[i].value != '') {
                    temp[formParam[i].name] = formParam[i].value;
                }
            }
            return temp;
        };


        detailFormatter = function (index, row) {
            var html = [];
            if (row.title) {
                html.push('<p><b>标题:</b> ' + row.title + '</p>');
            }
            if (row.address) {
                html.push('<p><b>地址:</b> ' + row.address + '</p>');
            }
            if (row.joinNum) {
                html.push('<p><b>参与人数:</b> ' + row.joinNum + '</p>');
            }
            if (row.beginTime) {
                html.push('<p><b>开始时间:</b> ' + row.beginTime + '</p>');
            }
            if (row.endTime) {
                html.push('<p><b>结束时间:</b> ' + row.endTime + '</p>');
            }
            if (row.state) {
                html.push('<p><b>状态</b> ' + row.state + '</p>');
            }
            return html.join('');
        } 

        rowStyle = function (row, index) {
            var classes = ['active', 'success', 'info', 'warning', 'danger'];
            if (index % 2 === 0 && index / 2 < classes.length) {
                return {
                    classes: classes[index / 2]
                };
            }
            return {};
        }

        $table.bootstrapTable({
            url: "activity/showActivityNingList",
            pagination: !0,
            showRefresh: !0,
            showToggle: !0,
            showColumns: !0,
            iconSize: "outline",
            striped: true, //是否显示行间隔色
            queryParams: queryParams,//传递参数（*）
            sidePagination: "server", //服务端处理分页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [5, 10, 20, 50],        //可供选择的每页的行数（*）
            minimunCountColumns: 2,      //可供选择的每页的行数（*）
            //detailView: true,
            sortName: undefined,
            sortOrder: 'asc',
            sortStable: false,
            type: "post",
            toolbar: "#tableEventsToolbar",
            contentType: "application/json; charset=utf-8",
            detailFormatter: detailFormatter,
            rowStyle: rowStyle,
            iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
            icons: {
                refresh: "glyphicon-repeat",
                toggle: "glyphicon-list-alt",
                columns: "glyphicon-list",
                detailOpen: 'glyphicon-plus icon-plus',
                detailClose: 'glyphicon-minus icon-minus',
                sortable: 'glyphicon-minus icon-minus'
            },
            onLoadSuccess: function (data) {
                if (data.total < 5) {
                    $table.bootstrapTable('getOptions')["height"] = 400;
                } else {
                    $table.bootstrapTable('getOptions')["height"] = 800;
                }

                $table.bootstrapTable('hideColumn', 'id');
            },
            columns: [
                {
                    title: '标题',
                    field: 'title',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '头像',
                    field: 'headPortrait',
                    align: 'center',
                    valign: 'middle',
                	formatter : function(value, row, index) {
						return '<img src="'+value+'" class="head-img" />';
					}
                },
                 {
                    title: '活动链接',
                    field: 'url',
                    align: 'center',
                    valign: 'middle'
                }, 
                 /* {
                    title: '活动描述',
                    field: 'description',
                    align: 'center',
                    valign: 'middle'
                },  */
                {
                    title: '开始时间',
                    field: 'beginTime',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
               	    	return CovertToDate(value);
                     }
                },
                {
                    title: '结束时间',
                    field: 'endTime',
                    align: 'center',
                    valign: 'middle',
               	    formatter: function (value, row, index) {
               	    	return CovertToDate(value);
                     }
                    	
                },
             
                
                {
                    title: '状态',
                    field: 'state',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                    	if(1==value){
                    		return "已结束";
                    	}else if(0==value){
                    		if(new Date(row.endTime)>new Date){
                    			return "进行中";
                    		}else{
                    			return "已结束";
                    		}
                    		
                    	}
                        
                    }
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    width : '140',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                    	return	'<a><button class="btn  btn-xs" id="editButton" onclick="editproviderDetail(\''+row.id+'\','+index+')" title="修改"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button></a>'+
                              '&nbsp;<a><button class="btn  btn-xs" onclick="delete_tr(\''+row.id+'\')" title="删除"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></a>';

                    }
                } 
            ]
        });
        for (var selector in config)$(selector).chosen(config[selector]);
    });

    function tableHeight() {
        return $(window).height() - 50;
    }
    var delete_tr_id = null;
    function delete_tr(a) {
    	var row = $table.bootstrapTable('getRowByUniqueId', a);
        var s = row.title;
        delete_tr_id = a;
      
        	$("#deletecontent").html("是否删除"+s);
        
        $("#tableShow").hide();
        $("#myModal").show();
    }
    function cancel() {
        $("#tableShow").show();
        $("#myModal").hide();
    }
    function confirm() {
    	
    		   $.ajax({
    	            url: "<%=basePath%>activity/toDeleteActivityVote",
    	            type: "post",
    	            data: {"id": delete_tr_id},
    	            dataType: "json",
    	            success: function (note) {
    	                $("#tableShow").show();
    	                $("#myModal").hide();
    	                $table.bootstrapTable('refresh');
    	            },
    	            error: function () {
    	                alert("删除异常，请稍后重试");
    	            }

    	        });
    	
     
    }
    

    
    var addOperator=function(){
    window.location.href="<%=basePath%>activity/toAddNingPage"; 
    }
    var editproviderDetail = function (id, index) {
    	var row = $table.bootstrapTable('getRowByUniqueId', id);
    	 window.location.href="<%=basePath%>activity/toEditNingPage?id="+id; 
    }

    function CovertToDate(unittime) {
        //3.转换成js时间格式
        var jsDate = new Date(unittime).Format("yyyy-MM-dd hh:mm:ss");
     	
        return jsDate;


    }
    Date.prototype.Format = function (fmt) { //author: meizz 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }


</script>
  </body>
</html>
